home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
network
/
pktdrvtp.zip
/
TRAFMON.ZIP
/
TRAFMON.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-09-28
|
13KB
|
352 lines
Program TrafficMonitor;
{
╔════════════════════════════════════════════════════════════════════════╗
║ TRAFMON Version 1.0 (Released to public domain) ║
╟────────────────────────────────────────────────────────────────────────╢
║ Author : O. Rehmann ║
║ ║
║ e-mail : 100016.732@compuserve.com ║
║ : CZ8OR@zcvx00.decnet.ascom.ch ║
╟────────────────────────────────────────────────────────────────────────╢
║ Sample program to monitor ethernet traffic. ║
╟────────────────────────────────────────────────────────────────────────╢
║ ATTENTION: ║
║ ║
║ The author can not be held responsible for any damages resulting out ║
║ of the use of this software !!! ║
║ ║
╚════════════════════════════════════════════════════════════════════════╝
}
{$A+,B-,D+,E-,F+,G-,I-,L+,N-,O-,R-,S-,V+,X+}
{$M $2048 $0 $8192}
USES CRT,DOS,STRINGS,TIMER,PKTDRVR;
CONST MaxEthernetCapacity = 1250000; { Max. theroetical ethernet capacity }
TYPE
{ 6 Byte ethernet address }
EthernetAddr = Array[00..05] of Byte;
MACHeader = RECORD { IEEE 802.3 header }
DestAddr : EthernetAddr;
SourceAddr : EthernetAddr;
TypeLen : Word;
END;
VAR Key : Char;
pktDriver : TPKTDRVR; { Instance of the TPKTDRVR object }
pktDriverInfo : TDRVRINFO; { record for driver information }
pktDriverAccess : TACCESSTYPE; { record used for accessing packet driver }
TypeField : Word;
RcvPacket : Array[00..1524] of Byte; { Rcv buffer }
RcvLength : Word; { Length of packet }
RcvHeader : MACheader; { Header }
PacketCount : Word; { Packet counter }
PacketDelay : Word;
CurTraffic : Real;
CumTraffic : LongInt;
VUMeterLen : Real;
MyTimer : _TIMER;
I : Integer;
{ ========================================================================== }
{ The receiver procedure: }
{$S-}PROCEDURE pktReceiver; ASSEMBLER;
ASM
PUSH AX { Push registers onto stack }
PUSH BX
PUSH CX
PUSH DX
CMP AX,0001 { AX=1 means frame copied }
JZ @@FrameCopied
CMP AX,0000 { AX=0 means allocate memory please }
JZ @@AllocMemory
JMP @@EXIT { Invalid register contents for AX so exit}
@@AllocMemory:
MOV DX,0 { ES:DI = 0000:0000, we don't want the packet }
MOV ES,DX
MOV DI,0 { We don't grab the packet }
MOV DX,SEG PacketCount { Set correct data segment }
MOV DS,DX
MOV DX,PacketCount
CMP DX,0
JNZ @@Exit { buffer is not free ! }
MOV DX,SEG rcvPacket
MOV ES,DX
MOV DI,OFFSET rcvPacket
MOV DX,SEG rcvLength
MOV DS,DX
MOV SI,OFFSET RcvLength
MOV WORD PTR DS:[SI],CX { Store length of frame in PacketLength }
JMP @@Exit
@@FrameCopied:
MOV DX,SEG PacketCount { Set correct data segment }
MOV DS,DX
MOV PacketCount,1 { Set Flag to 1 }
@@Exit:
POP DX { Pop registers from stack }
POP CX
POP BX
POP AX
END;
{$S+}
FUNCTION ByteToHEXASCII(tByte : Byte) : String;
{╔══════════════════════════════════════════════════════════════════════╗
║ FUNCTION ByteToHEXASCII (...) : String; ║
╟─────────────────┬────────────────────────────────────────────────────╢
║ Description : │ Converts Byte to a HEX-ASCII-String ║
║ │ requests. ║
╟─────────────────┼────────────────────────────────────────────────────╢
║ Creation date : │ 23-SEPT-93 ║
╚═════════════════╧════════════════════════════════════════════════════╝}
CONST
HEXChars: array [0..15] of char = '0123456789ABCDEF';
VAR Nibble1 : Byte;
Nibble2 : Byte;
tStr : String;
BEGIN
Nibble1 := (tByte AND $0F); { AND 00001111b }
Nibble2 := (tByte AND $F0) SHR 4; { AND 11110000b }
tStr := HEXChars[Nibble2]+HEXChars[Nibble1];
ByteToHEXASCII := tStr;
END;
FUNCTION WordToHEXASCII(tWord : Word) : String;
{╔══════════════════════════════════════════════════════════════════════╗
║ FUNCTION WordToHEXASCII (...) : String; ║
╟─────────────────┬────────────────────────────────────────────────────╢
║ Description : │ Converts tWord to a HEX-ASCII-String ║
║ │ requests. ║
╟─────────────────┼────────────────────────────────────────────────────╢
║ Creation date : │ 23-SEPT-93 ║
╚═════════════════╧════════════════════════════════════════════════════╝}
VAR tStr : String;
BEGIN
tStr := ByteToHexASCII(Hi(tWord));
tStr := tStr+ByteToHexASCII(Lo(tWord));
WordToHexASCII := tStr;
END;
{╔══════════════════════════════════════════════════════════════════════╗
║ FUNCTION GetEthernetAddress ║
╟─────────────────┬────────────────────────────────────────────────────╢
║ Description : │ Converts a 6 byte ethernet address into a dash ║
║ │ separated string. ║
╟─────────────────┼────────────────────────────────────────────────────╢
║ Creation date : │ 23-SEPT-93 ║
╚═════════════════╧════════════════════════════════════════════════════╝}
FUNCTION GetEthernetAddress(tEtherAddr : EthernetAddr) : String;
VAR tString : String;
tDigit : String[02];
tCount : Byte;
AddrLen : Byte;
BEGIN
AddrLen := SizeOf(EthernetAddr)-1;
tString := '';
FOR tCount := 0 TO AddrLen DO
BEGIN
tString := tString + ByteToHexASCII(tEtherAddr[tCount]);
IF (tCount < AddrLen) THEN tString := tString + '-';
END;
GetEthernetAddress := tString;
END;
PROCEDURE TranslateEthernetAddress(tStr : String; VAR tEtheraddr : EthernetAddr);
{╔══════════════════════════════════════════════════════════════════════╗
║ PROCEDURE TranslateEthernetAddress(..); ║
╟─────────────────┬────────────────────────────────────────────────────╢
║ Description : │ Translates a dash separated ethernet address into ║
║ │ 6 Bytes. ║
╟─────────────────┼────────────────────────────────────────────────────╢
║ Creation date : │ 23-SEPT-93 ║
╚═════════════════╧════════════════════════════════════════════════════╝}
VAR tDigit : String;
tByte : Byte;
Err : Integer;
tVal : Byte;
BEGIN
tDigit :='';
FOR tByte := 1 TO Length(tStr) DO
BEGIN
IF (Copy(tStr,tByte,1) <> '-') THEN tDigit := tDigit + Copy(tStr,tByte,1);
END;
FOR tByte := 0 TO 5 DO
BEGIN
Val('$'+Copy(tDigit,(tByte*2)+1,2),tVal,Err);
tEtheraddr[tByte] := tVal;
END;
END;
{╔══════════════════════════════════════════════════════════════════════╗
║ FUNCTION SwapWord; ║
╟─────────────────┬────────────────────────────────────────────────────╢
║ Description : │ Swaps the Hi and Lo byte of a word. ║
║ │ ║
╟─────────────────┼──